package com.ytkj.digitalConstruction.service.constructionprocess;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ytkj.digitalConstruction.dao.constructionprocess.ConstructionConcentrateNoticeMapper;
import com.ytkj.digitalConstruction.entity.constructionprocess.ConstructionConcentrateNotice;
import com.ytkj.digitalConstruction.entity.user.User;
import com.ytkj.digitalConstruction.httpbean.constructionprocess.resbean.WholeFlowInfo;

/**
 * 风险教育通知相关业务
 * 
 * @author 宁~
 *
 */
@Service
@Transactional
public class ConstructionConcentrateNoticeService {

	@Autowired
	private ConstructionConcentrateNoticeMapper constructionConcentrateNoticeMapper;
	
	@Autowired
	private ConstructionBaseService constructionBaseService;
	
	@Autowired
	private SendNoticeService sendNoticeService;
	
	/**
	 * @Description: 项目部确定收到通知
	 * @Title: confirmPlanOperating 
	 * @param @param flowId
	 * @param @return 
	 * @return WholeFlowInfo
	 * @throws
	 */
	public WholeFlowInfo confirmProject(Integer flowId, User user){
		//constructionBaseService.checkProcess(flowId, 5);
		
		// 更改施工计划文档的节点状态
		// 修改集结通知表
		ConstructionConcentrateNotice concentrateNotice = new ConstructionConcentrateNotice();
		concentrateNotice.setFlowId(flowId);
		patchConcentrateNotice(concentrateNotice, user);
		ConstructionUtilService.isUpdateSuccess(constructionConcentrateNoticeMapper.updateByFlowIdSelective(concentrateNotice));		
		
		//提前通知到达
		return constructionBaseService.showWholeFlowByFlowId(flowId);
	}
	
	/**
	 * @Description: 风险教育通知
	 * @Title: noticeRiskEdc 
	 * @param @param flowId
	 * @param @return 
	 * @return WholeFlowInfo
	 * @throws
	 */
	public void noticeRiskEdc(Integer flowId, WholeFlowInfo flowInfo, User user){
		String users = sendNoticeService.flowNoticeSend(4, flowInfo, user);
		
		//通知表增加数据
		ConstructionConcentrateNotice concentrateNotice = new ConstructionConcentrateNotice();
		concentrateNotice.setFlowId(flowId);
		concentrateNotice.setNotifyArriving(1);
		concentrateNotice.setRiskEdc(0);
		concentrateNotice.setStatus(1);
		concentrateNotice.setNoticeOperator(users);
		patchConcentrateNotice(concentrateNotice, user);
		concentrateNotice.setOperator("");
		constructionConcentrateNoticeMapper.insertSelective(concentrateNotice);
		ConstructionUtilService.isAddSuccess(concentrateNotice.getNoticeId());

	}
	
	/**
	 * @Description: 补全参数信息
	 * @Title: patchConcentrateNotice 
	 * @param @param concentrateNotice
	 * @param @param user 
	 * @return void
	 * @throws
	 */
	public void patchConcentrateNotice(ConstructionConcentrateNotice concentrateNotice, User user) {
		concentrateNotice.setOperator(String.valueOf(user.getUserId()));
		concentrateNotice.setUpdateBy(user.getUserId());
		concentrateNotice.setUpdateDate(new Date());
	}
	
	
}
